Codingassignmenthelper | Home Codingassignmenthelper | University

CST8110 Assignment 4 6510

Assignment :

What to submit : MyTakeOnISO3166.java

Challenge

In this last assignment, you will be playing with ISO-3166 content. This assignment will focus on twodimensional array, method calling, strings manipulation and more …

You need to create a class called MyTakeOnISO3166.java.

Your main method would call a non-static method called init which will populate a two-dimensional String array of 250 rows and variable length of columns. The rows will contain the country codes and the columns will contain the corresponding country names. The init method should not take any parameter and should not return anything as well.

In order to do this, you would be using the following sample code:

String[] countryCodes = Locale.getISOCountries();

And for each countryCode, you can create a new Locale object as below and get the country name
new Locale("", countryCode);

Then you need to provide another method that will be called getCountryName, which takes a country code and returns the corresponding country name using the two-dimensional array. This method needs to work on a country code regardless if it is lower case, upper case or a mix between the two. Country code is composed of two letters. If no match, it returns a null.

Also, you need a method called getCountryCode which takes a country name, as well, regardless if it is upper or lower case or a mix, and returns the appropriate country code in upper case format. If not match, it returns a null.

Now, you need an additional method, called getMatchedCountries, which takes a string of any set of characters and tries to match any country name that has this string in its name. You CANNOT use regular expressions since we do not study them in this course. You need to use methods from String class. As well, the string can be a mix of upper and lower case characters and the match is case insensitive; i.e. if the user enters “can”, this method needs to find all countries that have “Can” or “can” and all other combinations … in their names. This method needs to return an array of Strings. You can use ArraysList class as follows:

ArrayList<String> aList = new ArrayList<String>();
aList.add("Canada");
String[] tempArr = new String[aList.size()];
return (String[]) aList.toArray(tempArr);

The matching string cannot be less than two letters. If it is the case, the following message needs to be displayed “Matching string cannot be less than two letters, please enter another matching string: ” and you keep prompting the user for a valid matching string or bye

If the user enters a matching string of two letters, the program needs to look for a match into the country code as well as in the country names; otherwise, only in country names. Duplicates in this case are allowed. If you manage to remove them without the usage of a Set (or any of its related classes that implement this interface), you will have a bonus mark; but ONLY if all other features are complete and have no issue !

The result of this matching method needs to be displayed with one tab indentation as per below.

The result needs to start with the count of results records.
The result needs to display the country name followed by the country code in parentheses.
If no match, it returns a null.

You do all the displaying in main method. You do all the prompting for the user in main method.

Your main method needs to prompt the user for a country code/country name and needs to distinguish between the two. After listing the results, it will prompt the user for a matching string, displays the results and keep looping until the user enters the string bye, in any case sensitivity and at any point during the program execution (i.e. for country code/country name or for matching string).

If the user enters a country code, a country name or a valid matching string that does not match any of the loaded one, the program needs to return the following message “No match for country code entered”, “No match for country name entered” or “No match for matching string entered”.

Sample Output

Welcome to My Take on ISO-3166. Enter “bye” anytime to end.
Please enter a country code or a country name: CA
The country name for the country code entered CA is Canada
Please enter a matching string for the country names: ch
The list of countries for the matching string “ch” is the following:
Results count: 13
Switzerland (CH)
Chile (CL)
China (CN)
Christmas Island (CX)
… (I am not going to print the whole list but you got the idea)

Please enter a country code or a country name: C
Matching string cannot be less than two letters, please enter another matching string: D
Matching string cannot be less than two letters, please enter another matching string: DI
No match for country code entered. Please enter a country code or a country name: Cyprus
The country code for the country name entered CYPRUS is CY
Please enter a matching string for the country names: abcdef
No match for matching string entered

Please enter a country code or a country name: DK
The country name for the country code entered DK is Denmark
Please enter a matching string for the country names: bye


Bye


To Download Click Here > CST8110 Assignment 4 6510.pdf
Codingassignmenthelper | Home Codingassignmenthelper | Home